package cn.ken.student.rubcourse.service.impl;

import cn.ken.student.rubcourse.common.constant.WeekDayConstant;
import cn.ken.student.rubcourse.common.entity.Result;
import cn.ken.student.rubcourse.dto.req.StudentChooseLogReq;
import cn.ken.student.rubcourse.dto.resp.StudentChooseLogResp;
import cn.ken.student.rubcourse.entity.*;
import cn.ken.student.rubcourse.mapper.*;
import cn.ken.student.rubcourse.service.IStudentCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 学生选课表 服务实现类
 * </p>
 *
 * @author Ken-Chy129
 * @since 2022-11-16
 */
@Service
public class StudentCourseServiceImpl extends ServiceImpl<StudentCourseMapper, StudentCourse> implements IStudentCourseService {
    
    @Autowired
    private StudentCourseMapper studentCourseMapper;

    @Override
    public Result getStudentChooseLog(HttpServletRequest httpServletRequest, StudentChooseLogReq studentChooseLogReq) {
        List<StudentChooseLogResp> studentCourse = studentCourseMapper.getStudentChooseLogs(studentChooseLogReq);
        for (StudentChooseLogResp studentChooseLogResp : studentCourse) {
            List<CourseTimeplace> courseTimeplaceList = studentChooseLogResp.getCourseTimeplaceList();
            StringBuilder placeTime = new StringBuilder();
            for (CourseTimeplace courseTimeplace : courseTimeplaceList) {
                placeTime.append(courseTimeplace.getDurationTime()).append(" 星期").append(WeekDayConstant.INSTANCE.get(courseTimeplace.getWeekDay()-1)).append(" ").append(courseTimeplace.getDayNo()).append(" ").append(courseTimeplace.getPlace()).append("\n");
            }
            studentChooseLogResp.setPlaceTime(placeTime.toString());
        }
        return Result.success(studentCourse);
    }

}
